package com.library.mapper;

import com.github.pagehelper.Page;
import com.library.dto.FavoriteDTO;
import com.library.entity.UserFavorite;
import com.library.vo.FavoriteVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserFavoriteMapper {


    @Select("select * from user_favorite where user_id = #{userId} and book_id = #{bookId}")
    UserFavorite getByUserIdAndBookId(Long userId, Long bookId);

    void update(FavoriteDTO favoriteDTO);

    @Insert("insert into user_favorite(user_id, book_id, book_title,bookmark_position) " +
            "values(#{userId}, #{bookId},#{bookTitle}, #{bookmarkPosition})")
    void save(FavoriteDTO favoriteDTO);

    @Select("select * from user_favorite where user_id = #{userId}")
    Page<FavoriteVO> getByUserId(Long userId);

    @Delete("delete from user_favorite where book_id = #{bookId} and user_id = #{userId}")
    void delete(Long bookId, Long userId);
}
